let nodemailer = require("nodemailer");
let mailConfig = {
   user: `yimeiqianduan@lovecd.com`,
   pass: `密码`
};
let mailTransport = nodemailer.createTransport({
  host: "smtpdm.aliyun.com",
  port:465,
  // host: 'smtp.qq.com',
  secureConnection: true, // 使用SSL方式（安全方式，防止被窃取信息）
  auth: {
    user: mailConfig.user,
    pass: mailConfig.pass
  }
});
let options = {
  from: `${mailConfig.user}`,
  to: "*****@qq.com",
  // cc         : ''  //抄送
  // bcc      : ''    //密送
  subject: "一封来自Node Mailer的邮件",
  text: "一封来自Node Mailer的邮件",
  html:
    '<h1>你好，这是一封来自NodeMailer的邮件！</h1><p><img src="cid:00000001"/></p>'
  // attachments:[{
  //     filename : 'SZGS1C',
  //     path: '../public/images/tg_laop.jpg'
  // },{
  //     filename : 'package.json',
  //     path: './package.json'
  // }]
};
module.exports = {
  put: option => {
    option = { ...options, ...option };
    mailTransport.sendMail(option, (err, info) => {
      let bool = true;
      if (err) {
        console.error(err);
        bool = false;
      }
      typeof option.callback == "function" ? option.callback(bool) : "";
    });
  }
};
